<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Jobs\GrabGarbageJob;

/**
 * 从电厂获取抓斗数据并保存到本地
 */
class GrabGarbageCmd extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'collect:grabGarbage {--date=default}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'collect grabGarbage';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $optionDate = $this->option('date');
        if($optionDate != 'default'){
            $date = $optionDate;
        }
        else{
            $date = date('Y-m-d');
        }

        $params = array(
            'date' => $date,
            'factory_conn' => "mysql_grab",
            'local_conn' => "sqlsrv—local",
            'factory_data_table' => "log",
            'local_data_table' => "grab_garbage_yongqiang1"
        );

        dispatch(new GrabGarbageJob($params));

        return 0;
    }
}
